<?php /* TASKS $Id: viewgantt.php,v 1.7.4.8 2006/12/27 18:50:43 gregorerhardt Exp $ */
GLOBAL  $AppUI, $dPconfig, $company_id, $dept_ids, $department, $min_view, $m, $a, $user_id, $tab, $pstatus;
//Secho dPgetConfig( 'jpLocale' );
ini_set('memory_limit', $dPconfig['reset_memory_limit']);

$min_view = defVal( @$min_view, false);
$project_id = defVal( @$_GET['project_id'], 0);
$user_id = defVal( @$_GET['user_id'], $AppUI->user_id);
// sdate and edate passed as unix time stamps
$sdate = dPgetParam( $_POST, 'sdate', 0 );
$edate = dPgetParam( $_POST, 'edate', 0 );
$showInactive = dPgetParam( $_POST, 'showInactive', '0' );
$showLabels = dPgetParam( $_POST, 'showLabels', '0' );
$sortTasksByName = dPgetParam( $_POST, 'sortTasksByName', '0' );
$showAllGantt = dPgetParam( $_POST, 'showAllGantt', '0' );
$showTaskGantt = dPgetParam( $_POST, 'showTaskGantt', '0' );
$addPwOiD = dPgetParam($_POST, 'add_pwoid', 0);

//if set GantChart includes user labels as captions of every GantBar
if ($showLabels!='0') {
    $showLabels='1';
}
if ($showInactive!='0') {
    $showInactive='1';
}

if ($showAllGantt!='0') {
     $showAllGantt='1';
}

if (isset(  $_POST['proFilter'] )) {
	$AppUI->setState( 'ProjectIdxFilter',  $_POST['proFilter'] );
}
$proFilter = $AppUI->getState( 'ProjectIdxFilter' ) !== NULL ? $AppUI->getState( 'ProjectIdxFilter' ) : '-1';

$projFilter = arrayMerge( array('-1' => 'All Projects'), $pstatus);
$projFilter = arrayMerge( array( '-2' => 'All w/o in progress'), $projFilter);
if ($AppUI->user_id == $user_id) {
	$projFilter = arrayMerge( array( '-3' => 'My projects'), $projFilter);
} else {
	$projFilter = arrayMerge( array( '-3' => 'User\'s projects'), $projFilter);
}

natsort($projFilter);


// months to scroll
$scroll_date = 1;

$display_option = dPgetParam( $_POST, 'display_option', 'this_month' );

// format dates
$df = $AppUI->getPref('SHDATEFORMAT');

if ($display_option == 'custom') {
	// custom dates
	$start_date = intval( $sdate ) ? new CDate( $sdate ) : new CDate();
	$end_date = intval( $edate ) ? new CDate( $edate ) : new CDate();
} else {
	// month
	$start_date = new CDate();
	$start_date->day = 1;
   	$end_date = new CDate($start_date);
    $end_date->addMonths( $scroll_date );
}

// setup the title block
if (!@$min_view) {
	$titleBlock = new CTitleBlock( 'Gantt Chart' );
	$titleBlock->addButton('projects list',  '?m=projects');
	$titleBlock->show();
}

?>

<script language="javascript">

function scrollPrev() {
	f = document.editFrm;
<?php
	$new_start = $start_date;
	$new_start->day = 1;
	$new_end = $end_date;
	$new_start->addMonths( -$scroll_date );
	$new_end->addMonths( -$scroll_date );

	echo "f.sdate.value='".$new_start->format( FMT_TIMESTAMP_DATE )."';";
	echo "f.edate.value='".$new_end->format( FMT_TIMESTAMP_DATE )."';";
?>
	document.editFrm.display_option.value = 'custom';
	f.submit()
}

function scrollNext() {
	f = document.editFrm;
<?php
	$new_start = $start_date;
	$new_start->day = 1;
	$new_end = $end_date;
	$new_start->addMonths( $scroll_date );
	$new_end->addMonths( $scroll_date );
	echo "f.sdate.value='" . $new_start->format( FMT_TIMESTAMP_DATE ) . "';";
	echo "f.edate.value='" . $new_end->format( FMT_TIMESTAMP_DATE ) . "';";
?>
	document.editFrm.display_option.value = 'custom';
	f.submit()
}

function showThisMonth() {
	document.editFrm.display_option.value = "this_month";
	document.editFrm.submit();
}

function showFullProject() {
	document.editFrm.display_option.value = "all";
	document.editFrm.submit();
}

Calendar.enabled = true;
</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td>
		<table border="0" cellpadding="4" cellspacing="0" class="subinfopanel" width="100%">
			<form name="editFrm" method="post" action="?<?php echo 'm='.$m.'&a='.$a. (isset($user_id) ? '&user_id='.$user_id : '').'&tab='.$tab;?>">
			<input type="hidden" name="display_option" value="<?php echo $display_option;?>" />
			<tr>
				<td align="left" width="20">
				<?php if ($display_option != "all") { ?>
					<img class="clickable" src="images/prev.gif" title="<?php echo $AppUI->_( 'previous' );?>"
						onclick="scrollPrev()">
                <?php } ?>
				</td>
				<td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'From' );?>:</td>
				<td align="left" nowrap="nowrap">
					<input id="idDateStart" type="hidden" name="sdate" value="<?php echo $start_date->format( FMT_TIMESTAMP_DATE );?>" />
					<input id="idDateStartD" type="text" class="text" name="show_sdate" value="<?php echo $start_date->format( $df );?>" size="12" disabled="disabled" />
				</td>
				<td style="padding-left: 0px; margin: 0px">
					<img id="idDateStartB" class="clickable" src="images/calendar.gif"/>
				</td>
				<td align="right" nowrap="nowrap"><?php echo $AppUI->_( 'to' );?>:</td>
				<td align="left" nowrap="nowrap">
					<input id="idDateEnd" type="hidden" name="edate" value="<?php echo $end_date->format( FMT_TIMESTAMP_DATE );?>" />
					<input id="idDateEndD" type="text" class="text" name="show_edate" value="<?php echo $end_date->format( $df );?>" size="12" disabled="disabled" />
				</td>
				<td style="padding-left: 0px; margin: 0px">
					<img id="idDateEndB" class="clickable" src="images/calendar.gif"/>
				</td>
				<td width="20">
                <?php if ($display_option != "all") { ?>
					<img class="clickable" src="images/next.gif" title="<?php echo $AppUI->_( 'next' );?>" onclick="scrollNext()">
                <?php } ?>
				</td>
				<td>
					<?php echo arraySelect( $projFilter, 'proFilter', 'size=1 class=text', $proFilter, true );?>
				</td>
				<td align="left" width="100%">
					<input type="button" class="button" value="<?php echo $AppUI->_( 'submit' );?>" onclick='document.editFrm.display_option.value="custom";submit();'>
				</td>
			</tr>
			<tr>
				<td colspan="100%">
					<table>
						<tr>
						<td><input id="idSL" type="checkbox" value='1' name="showLabels" <?php echo (($showLabels==1) ? "checked=true" : "");?>></td>
						<td><label for="idSL"><?php echo $AppUI->_( 'Show captions' );?></label></td>
						<td><input id="idSI" type="checkbox" value='1' name="showInactive" <?php echo (($showInactive==1) ? "checked=true" : "");?>></td>
						<td><label for="idSI"><?php echo $AppUI->_( 'Show Archived' );?></label></td>
						<td><input id="idSA" type="checkbox" value='1' name="showAllGantt" <?php echo (($showAllGantt==1) ? "checked=true" : "");?>></td>
						<td><label for="idSA"><?php echo $AppUI->_( 'Show Tasks' );?></label></td>
						<td><input id="idST" type="checkbox" value='1' name="sortTasksByName" <?php echo (($sortTasksByName==1) ? "checked=true" : "");?>></td>
						<td><label for="idST"><?php echo $AppUI->_( 'Sort Tasks By Name' );?></label></td>
						</tr>
					</table>
				</td>
			</tr>
			</form>
			<tr>
				<td align="center" valign="bottom" colspan="100%">
					<?php echo "<a href='javascript:showThisMonth()'>".$AppUI->_('Show this month')."</a> : <a href='javascript:showFullProject()'>".$AppUI->_('Show all')."</a><br>"; ?>
				</td>
			</tr>
		</table>
		<table cellspacing="0" cellpadding="0" border="0" align="center" class="subinfopanel" width="100%">
			<tr bgcolor="white">
				<td>
				<div style="overflow: auto; width: 100%; height: 300px; padding: 0px; margin: 0px; virtical-align: top" align="center">
                <?php
                	$src = "?m=projects&a=gantt&suppressHeaders=1" .
                ( $display_option == 'all' ? '' :
                  '&start_date=' . $start_date->format( "%Y-%m-%d" ) . '&end_date=' . $end_date->format( "%Y-%m-%d" ) ) .
                "&width=' + ((navigator.appName=='Netscape'?window.innerWidth:document.body.offsetWidth)-150) + '&showLabels=$showLabels&sortTasksByName=$sortTasksByName&proFilter=$proFilter&showInactive=$showInactive&company_id=$company_id&department=$department&dept_ids=$dept_ids&showAllGantt=$showAllGantt&user_id=$user_id&addPwOiD=$addPwOiD";
                echo "<script>document.write('<img src=\"$src\">')</script>";
                ?>
                </div>
				</td>
			</tr>
		</table>
	</td>
</tr>
</table>
<?php ini_restore('memory_limit');?>
